package com.wjc.train.business.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjc.train.business.req.TrainStationQueryReq;
import com.wjc.train.business.req.TrainStationSaveReq;
import com.wjc.train.business.resp.TrainStationQueryResp;
import com.wjc.train.business.service.ITrainStationService;
import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.common.untils.PageUtil;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 车站表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-08-02
 */
@RestController
@Validated
@RequestMapping("/admin/train-station")
public class TrainStationController {

    @Resource
    private ITrainStationService trainstationService;

    @PostMapping("/save")
    public CommonResp save(@RequestBody @Valid TrainStationSaveReq trainstationSaveReq){
        trainstationService.save(trainstationSaveReq);
        return CommonResp.success();
    }

    @PostMapping("/query-list")
    public CommonResp save(@RequestBody TrainStationQueryReq trainstationQueryReq){
        IPage<TrainStationQueryResp> iPage =
        trainstationService.queryList(PageUtil.getPage(trainstationQueryReq.getQueryPage()), trainstationQueryReq);
        return CommonResp.success(new PageUtil(iPage));
    }

    @DeleteMapping ("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        trainstationService.delete(id);
        return CommonResp.success();
    }


}


